import { createApp } from "vue";
import App from "./App.vue";

import type { VueMetaEnv } from "jmash-core";

import jmash, {
  store,
  routerRef,
  directive,
  useUserStore,
  getQueryParams,
  i18n,
  updateMetaEnv,
  axiosConfig,
} from "jmash-core";

//环境变量
const viteMetaEnv: ImportMetaEnv = import.meta.env;
const metaEnv: VueMetaEnv = {
  APP_PORT: viteMetaEnv.VITE_APP_PORT,
  APP_BASE_URL: viteMetaEnv.VITE_APP_BASE_URL,
  APP_BASE_API: viteMetaEnv.VITE_APP_BASE_API,
  APP_API_URL: viteMetaEnv.VITE_APP_API_URL,
  APP_CLIENT_ID: viteMetaEnv.VITE_APP_CLIENT_ID,
  APP_TENANT: viteMetaEnv.VITE_APP_TENANT,
};
updateMetaEnv(metaEnv);
axiosConfig(metaEnv);

import "@/permission";
import "jmash-core/dist/style.css";

const app = createApp(App);
//Query参数
const queryParams = getQueryParams();
if (queryParams.tenant) {
  useUserStore().user.tenant = queryParams.tenant;
} else {
  useUserStore().user.tenant = "region";
}

import region from "./index";
import dict from "jmash-dict";
import rbac from "jmash-rbac";

app
  .use(jmash)
  .use(dict)
  .use(rbac)
  .use(region)
  .use(directive)
  .use(store)
  .use(routerRef.value)
  .use(i18n)
  .mount("#app");
